<#assign tit>会员出入场</#assign>
<@page.html title=tit>
<script type="text/javascript">
  function loadInList() {
    loadHtml("div_list", "getInList");
  }

  var _lscd = null;
  function chkEnter(fm) {
    var c = fm.code.value;
    if(c!="") {
      if(_lscd==c) return false;
      _lscd = c;
      getJson("chkEnter?code="+encodeURIComponent(c), function(data){
        if(data.ret) {
          var mb = data.data;
          loadHtml("div_info", "getInfo?memberCode="+encodeURIComponent(mb.memberCode), null, function(){
            window.setTimeout(function(){setConf(mb);}, 200);
          });
        } else {
          window.alert(data.msg);
          cls();
        }
      });
    } else {
      cls();
    }
    return false;
  }

  var _mbinfo = null;
  function enter(t) {
    if(!_mbinfo) return;
    if(t==3 || t==4) {
      if(!window.confirm("确认要开卡吗")) return;
    }
    getJson("_add?memberCode="+_mbinfo.memberCode+"&tp="+t, function(data){
      if(data.ret) {
        cls();
        loadInList();
        if(data.msg) window.alert(data.msg);
        if(data.data && data.data.ptb && data.data.ptb.length>0) {
          if(t==2) {
            if(window.confirm("是否打印私教小票?")) {
              for(var i=0; i<data.data.ptb.length; i++)
                window.open("../ptBespeak/print?id="+data.data.ptb[i], true);
            }
          } else {
            window.alert("有预约私教");
          }
        }
      } else {
        window.alert(data.msg);
      }
    });
  }

  function setConf(mb) {
    _mbinfo = mb;
    var ss;
    if(mb.status==1)
      ss = '<div class="canenter" onclick="enter(1);">'+mb.memberName+', 请点击入场!</div>';
    else if(mb.status==2)
      ss = '<div class="canenter" onclick="enter(2);">'+mb.memberName+', 请点击出场!</div>';
    else if(mb.status==3)
      ss = '<div class="stopcard" onclick="enter(3);">停卡中, 请确认是否开卡?</div>';
    else if(mb.status==4)
      ss = '<div class="stopcard" onclick="enter(4);">请确认是否提前开卡?</div>';
    else
      ss = '<div class="notenter">'+mb.memberName+', '+mb.msg+'</div>';
    ss += '<div class="cancel" onclick="cls();" ">取消</div>';
    var div = getEl("div_conf");
    if(div) {
      div.innerHTML = ss;
      div.style.display = "";
    }
    //提示入场
    if(mb.status==1) {
      if(window.confirm(mb.memberName+", 确认要入场吗?"))
        enter(1);
      else
        cls();
    }
    //提示出场
    if(mb.status==2) {
      if(window.confirm(mb.memberName+", 确认要出场吗?"))
        enter(2);
      else
        cls();
    }
  }
  function cls() {
    _mbinfo = null;
    var div = getEl("div_conf");
    if(div) {
      div.innerHTML = "";
      div.style.display = "none";
    }
    div = getEl("div_info");
    if(div) div.innerHTML = "";
    var ipt = getEl("ipt_code");
    if(ipt) {
      ipt.value = "";
      ipt.focus();
    }
    _lscd = null;
  }

</script>

<div style="float:left; width:480px; min-height:300px;">
  <div class="kbox">
    <div class="search">
      <form method="post" onsubmit="return chkEnter(this);">
        <dl>
          <dd></dd>
          <dd><input type="text" name="code" id="ipt_code" value="" placeholder="请刷会员卡/身份证/二维码" style="width:260px;" /></dd>
          <dd class="button"><input type="submit" value="入场"></dd>
        </dl>
      </form>
    </div>

    <div id="div_info" style="min-height:220px; padding-top:15px;"></div>

  </div>

  <div id="div_conf" class="ent_conf" style="display:none;"></div>

</div>

<div id="div_list" style="float:left; margin-left:20px; width:350px;"></div>
<script type="text/javascript">loadInList();cls();</script>
</@page.html>